package cn.livingCloud.dto;

import cn.livingCloud.entity.core.EmployeeAccount;
import cn.livingCloud.entity.user.AccountPrivilege;
import cn.livingCloud.entity.user.Privilege;
import cn.livingCloud.entity.user.UserAccount;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 唐旭 on 2016/6/1.
 */
public class EmployeeAccountFormDto extends UserAccountFormDto {
    private String employeeUuid;
    private EmployeeDto employeeDto;
    private List<Privilege> currentPrivileges = new ArrayList<>();
    private boolean continuation = false;

    public EmployeeAccountFormDto() {
    }

    public EmployeeAccountFormDto(EmployeeAccount account) {
        this.uuid = account.getUuid();
        this.username = account.getUsername();
        this.password = account.getPassword();
        this.employeeUuid = account.getEmployeeUuid();
        this.employeeDto = new EmployeeDto(account.getEmployee());
        for (AccountPrivilege accountPrivilege : account.getAccountPrivilegeList()) {
            privilegeList.add(accountPrivilege.getPrivilege());
        }
    }

    public EmployeeAccountFormDto(UserAccount userAccount) {
        super(userAccount);
    }

    public EmployeeDto getEmployeeDto() {
        return employeeDto;
    }

    public EmployeeAccountFormDto setEmployeeDto(EmployeeDto employeeDto) {
        this.employeeDto = employeeDto;
        return this;
    }

    public String getEmployeeUuid() {
        return employeeUuid;
    }

    public EmployeeAccountFormDto setEmployeeUuid(String employeeUuid) {
        this.employeeUuid = employeeUuid;
        return this;
    }

    public void updateEmployeeAccount(EmployeeAccount account) {
        account.setEmployeeUuid(this.employeeUuid);
        account.setUsername(this.username);
        account.setPassword(this.password);
    }

//    @Override
//    public Privilege[] getAllPrivilege() {
//        List<Privilege> privilegeList = new ArrayList<>();
//        Privilege[] allPrivilege = super.getAllPrivilege();
//        for (Privilege privilege : allPrivilege) {
//            if (privilege.isEmployee()) {
//                privilegeList.add(privilege);
//            }
//        }
//        Privilege[] temp = new Privilege[0];
//        return privilegeList.toArray(temp);
//    }


    public List<Privilege> getCurrentPrivileges() {
        return currentPrivileges;
    }

    public EmployeeAccountFormDto setCurrentPrivileges(ArrayList<Privilege> currentPrivileges) {
        this.currentPrivileges = currentPrivileges;
        return this;
    }

    public boolean isContinuation() {
        return continuation;
    }

    public EmployeeAccountFormDto setContinuation(boolean continuation) {
        this.continuation = continuation;
        return this;
    }
}
